<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>故障诊断工具</title>
    <!--<base href="http://localhost:63342/NodeTest/"/>-->
    <link rel="stylesheet" href="../css/main.min.css">
    <script src="../js/main.min.js"></script>
    <script src="./select2.js"></script>
    <script src="../base/core.js"></script>
    <script src="faultTrain.js"></script>
    <script src="node-tree-view.js"></script>
    <link rel="stylesheet" href="treeview.css">
    <style>
        #faultTreeDiv div{
            border:2px solid black;
        }
    </style>
    <style media="print">
        .no-print { display: none }
        .page-next{ page-break-after: always }
    </style>
</head>
<body ng-app="myApp" ng-controller="manageController">
<div class="container-fluid">
    <div class="row">
        <form class="form-inline">
            <div class="form-group">
                <label>故障大类</label>
                <select class="form-control" data-ng-model="query.faultSuperType" data-ng-options="x.id as x.label for x in [{id:1,label:'火电'},{id:2,label:'水电'}]"></select>
            </div>
            <div class="form-group">
                <label>故障分组</label>
                <!--<select class="form-control" data-ng-model="query.faultType" data-ng-options="x for x in ['发电机','水电','锅炉','汽轮机','测试']">-->
                <select ng-if="query.faultSuperType==1" class="form-control" data-ng-model="query.faultType" data-ng-options="x for x in ['汽轮发电机','汽轮机','锅炉','测试']"></select>
                <select ng-if="query.faultSuperType==2" class="form-control" data-ng-model="query.faultType" data-ng-options="x for x in ['水轮发电机','水轮机','辅机','测试']"></select>
                <select ng-if="query.faultSuperType!=1 && query.faultSuperType!=2" class="form-control" data-ng-model="query.faultType" data-ng-options="x for x in ['汽轮发电机','水轮发电机','汽轮机','锅炉','水轮机','辅机','测试']"></select>
            </div>
            <div class="form-group">
                <label>故障模块</label>
                <select class="form-control" data-ng-model="query.faultModule" data-ng-options="x.name as x.name for x in faultModules | filter:{'category':query.faultType} "></select>
            </div>
            <div class="form-group">
                <label>故障名称</label>
                <select class="form-control" data-ng-model="query.fault" data-ng-options="('<'+fault.outId+'>'+ fault.name) for fault in faults | filter:filterOfFault | orderBy:sortByOutId"></select>
            </div>
            <div class="form-group">
                <label></label>
                <p class="form-control-static">
                    <!--<a class="btn btn-default" href="javascript:;" ng-click="persistGraph()" >同步到数据库</a>-->
                    <!--<a class="btn btn-default" href="javascript:;" ng-click="persistGraphClone()" >复制一个新的到数据库</a>-->
                    <!--<a class="btn btn-default" href="javascript:;" ng-click="createNewGraph()" >添加新故障</a>-->
                    <!--<a class="btn btn-default" href="javascript:;" ng-click="deleteFault()" >删除该故障</a>-->
                    <!--<a class="btn btn-default" href="javascript:;" ng-click="refreshFaults()" >刷新故障列表</a>-->
                    <a class="btn btn-default" href="javascript:;" ng-click="nextFaults()" >下一个故障</a>
                    <a class="btn btn-default" href="javascript:;" ng-click="exportFaultAsJson()" >确认故障调整结果</a>
                </p>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-md-4">
            <div class="panel" style="height: 350px">
                <div class="panel-heading">故障树&nbsp;<a href="javascript:;" ng-click="graphTree.collapseAll()">展开所有节点</a> </div>
                <div class="panel-body treeDiv" id="treeDiv"></div>
            </div>
        </div>
        <div class="col-md-8">
            <div class="row" ng-show="query.fault!=null">
                <table class="table table-responsive table-bordered">
                    <thead>
                    <tr><td>特征/原因</td><td ng-repeat="reason in graph.getReasons() track by $index">{{reason.getText()}}</td><td>整体</td></tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="feature in graph.getFeatures() track by $index" ng-init="$index2=$index">
                        <td>{{feature.getText()}}</td><td ng-repeat="reason in graph.getReasons() track by $index">
                        <input class="form-control" data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" data-ng-model="graph.getRoot().matrix[$index2*(graph.getReasons().length+1)+$index+2]">
                    </td><td> <input class="form-control" data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" data-ng-model="graph.getRoot().matrix[($index2+1)*(nr+1)+1]"></td>
                    </tr>
                    </tbody>
                    <tfoot><tr>
                        <td>整体</td><td ng-repeat="reason in graph.getReasons() track by $index">
                        <input class="form-control" data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" data-ng-model="graph.getRoot().matrix[(graph.getFeatures().length)*(graph.getReasons().length+1)+$index+2]">
                    </td><td><input class="form-control" data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" data-ng-model="graph.getRoot().matrix[(graph.getFeatures().length+1)*(graph.getReasons().length+1)+1]"></td>
                    </tr></tfoot>
                </table>
            </div>
            <div class="row">
                <a class="btn btn-default" href="javascript:;" ng-click="initSamples()" >初始化模型</a>
            </div>
        </div>
    </div>
    <div class="row">
        <p>选择成立的特征：</p>
        <form class="form-inline">
            <div class="form-group" ng-repeat="feature in graph.getFeatures() track by $index">
                <label>{{feature.getText()}}</label>
                <input type="checkbox" ng-model="featureChoice[$index]">
            </div>
        </form>
        <p><a class="btn btn-default" href="javascript:;" ng-click="featFeature()" >计算各原因的发生概率</a></p>
        <table class="table table-responsive table-bordered" ng-show="featResult.length>0">
            <thead><tr>
                <th>原因</th><th>保守概率</th><th>相对概率</th><th>均衡概率</th>
            </tr></thead>
            <tbody>
            <tr ng-repeat="frow in featResult track by $index">
                <td>{{graph.getReasons()[$index].getText()}}</td>
                <td>{{frow[0]}}</td>
                <td>{{frow[1]}}</td>
                <td>{{frow[2]}}</td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="row" ng-show="featResult.length>0">
        <p>添加专家判断（选出专家认为成立的原因）：</p>
        <form class="form-inline">
            <div class="form-group" ng-repeat="reason in graph.getReasons() track by $index">
                <label>{{reason.getText()}}</label>
                <input type="checkbox" ng-model="reasonChoice[$index]">
            </div>
        </form>
        <p><a class="btn btn-default" href="javascript:;" ng-click="trainFeature()" >使用专家的判断进行调整</a></p>
        <p ng-show="featResult2.length>0">调整后上面的案例的概率更新为：</p>
        <table class="table table-responsive table-bordered" ng-show="featResult2.length>0">
            <thead><tr>
                <th>原因</th><th>保守概率</th><th>相对概率</th><th>均衡概率</th>
            </tr></thead>
            <tbody>
            <tr ng-repeat="frow in featResult2 track by $index">
                <td>{{graph.getReasons()[$index].getText()}}</td>
                <td>{{frow[0]}}</td>
                <td>{{frow[1]}}</td>
                <td>{{frow[2]}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>